#include "../StdAfx.h"
#include "xMesh.h"
#include "xSkin.h"
#include "xSkeleton.h"
#include "xLogManager.h"
#include "xMaterial.h"
#include "xMeshManager.h"


namespace XE
{

	const xString xMesh::Resource_Type = "Mesh";

	xMesh::xMesh(const xString& name,xResourceHandle handle)
		:xResource(name,handle),m_pSkin(NULL),m_lasttime(0.0f),m_Radius(0.0f)
		,m_SubMeshCount(0)
		
	{

	}

	xMesh::~xMesh(void)
	{
		SafeDelete(m_pSkin)
	//	SafeDelete(m_pSKeleton)

	}

	





	 xMaterialPtr	 xMesh::GetSubMeshMaterial(UINT SubIndex) const
	 {
		 if(SubIndex>m_MaterialVector.size()-1)
			 return xMaterialPtr();
		 return m_MaterialVector.at(SubIndex);

	 }

	 bool xMesh::SetSubMeshMaterial(UINT SubIndex,xMaterialPtr	 pMat)
	 {
		 if(SubIndex>=m_MaterialVector.size())
		 {
			 m_MaterialVector.resize(SubIndex+1);
		 }

		 m_MaterialVector[SubIndex] = pMat;
		 m_SubMeshCount = m_MaterialVector.size();

		 return true;
	 }

	 bool xMesh::SetSubMeshMaterial(UINT SubIndex,const xString& name)
	 {
		 xMaterialPtr pmat =xMaterialManager::getSingleton().GetByName(name);
		 if(pmat.isNull()==false)
		 {
			 return SetSubMeshMaterial(SubIndex,pmat);
		 }
		 return true;
	 }

}
